package com.project.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.entity.po.User;

import com.project.entity.qo.UserQo;
import com.project.result.ResponseResult;
import com.project.service.AdminService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ProjectName:
 * @Package:
 * @ClassName:
 * @Author: ZhaoLongShi
 * @CreateDate:
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/admin")
@RequiresRoles("admin")
public class AdminController {

    @Resource
    private AdminService adminService;

    /**
     * 查询所有用户（分页）
     *
     * @return
     */
    @GetMapping("/select/all/user")
    public ResponseResult selectAllUser(int current) {
        ResponseResult<Page<User>> result = adminService.selectAllUser(current);
        return result;
    }


    /**
     * 根据用户ID更新用户信息
     *
     * @param userQo
     * @return
     */
    @PostMapping("/update/user")
    public ResponseResult updateUserById(@RequestBody UserQo userQo) {
        ResponseResult result = adminService.updateUserById(userQo);
        return result;
    }


    /**
     * 根据用户ID删除用户（可批量）
     *
     * @param idList
     * @return
     */
    @PostMapping("/delete/user")
    public ResponseResult deleteUserByIds(@RequestParam("idList") List<Long> idList) {
        ResponseResult result = adminService.deleteUserByIds(idList);
        return result;
    }


    /**
     * 添加用户
     *
     * @param userQo
     * @return
     */
    @PutMapping("/add/user")
    public ResponseResult addUser(@RequestBody UserQo userQo) {
        ResponseResult result = adminService.addUser(userQo);
        return result;
    }


}
